$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});
function update() {
    var phone = $("input[name=contactMobile]").val();
    if (!/^[1][3-9][0-9]{9}$/.test(phone)) {
        parent.layer.alert("手机号码不正确");
        return;
    }
    
    var data = $('#signupForm').serialize();
    var joinType = $("#joinType").val();
    if('1' == joinType){
        var userIds = '';
        $(".userDiv").each(function(){
            var id = $(this).attr("user_id");
            userIds += id +",";
        });
        if(!userIds){
            parent.layer.alert("请选择参与人员");
            return;
        }
        data = data +"&userIds=" + userIds;
    }
    
	$.ajax({
		cache : true,
		type : "POST",
		url : ctx+"invest/company/update",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules : {
            name : {
                required : true
            },
            contactUser : {
                required : true
            },
            contactMobile : {
                required : true
            },
            address : {
                required : true
            },
            introDesc : {
                required : true
            }
        },
        messages : {
            name : {
                required : icon + "请输入名称"
            },
            contactUser : {
                required : icon + "请输入联系人"
            },
            contactMobile : {
                required : icon + "请输入联系电话"
            },
            address : {
                required : icon + "请输入地址"
            },
            introDesc : {
                required : icon + "请输入简介"
            }
        }
    })
}